package mianshi.alibaba;

import java.util.Scanner;

// dfs
public class T2 {
    static int[] dx = {-1, 1, 0, 0};
    static int[] dy = {0, 0, -1, 1};
    static int count=0;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] nums = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                nums[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                dfs(nums, i,j );
                count++;
            }
        }

        System.out.println(count);
    }

    private static void dfs(int[][] nums, int x, int y) {
        if (x < 0 || x >= nums.length || y < 0 || y >= nums[0].length||nums[x][y]==1){
            return;
        }


        for (int i = 0; i < 4; i++) {
            int mx = x+dx[i];
            int my = y+dy[i];
            dfs(nums,mx,my);
        }
    }
}
